package com.itheima.sc.web.sms;


import com.itheima.sc.pojo.sms.FlashPromotionSession;
import com.itheima.sc.result.Result;
import com.itheima.sc.service.sms.SmsFlashSessionService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/flashSession")
public class SmsFlashSessionController {

    @Autowired
    private SmsFlashSessionService sessionService;

    //添加
    @PostMapping("/create")
    public Result createFlashSession(@RequestBody FlashPromotionSession promotionSession){
        sessionService.addFlashSession(promotionSession);
        return Result.success(null);
    }
    //删除
    @PostMapping("/delete/{id}")
    public Result deleteFlashSession(@PathVariable("id")Long id){
        sessionService.deleteFlashSession(id);
        return Result.success(null);
    }

    //查询
    @GetMapping("/list")
    public Result getFlashSessionList(){
       List<FlashPromotionSession> sessionList= sessionService.getFlashSessionList();
        return Result.success(sessionList);
    }

    //获取全部可选场次及其数量
    @GetMapping("/selectList")
    public Result getFlashSessionSelectList(@RequestParam("flashPromotionId") Integer flashPromotionId){
        List<FlashPromotionSession> sessionList= sessionService.getFlashSessionSelectList(flashPromotionId);
        return Result.success(sessionList);
    }
    //修改启用状态
    @PostMapping("/update/status/{id}")
     public Result updateFlashSessionStatus(@PathVariable("id")Long id,Integer status){
        sessionService.updateFlashSessionStatus(id,status);
        return Result.success(null);
    }
    //修改场次
    @PostMapping("/update/{id}")
    public Result updateFlashSession(@PathVariable("id")Long id,@RequestBody FlashPromotionSession session){
        sessionService.updateFlashSession(id,session);
        return Result.success(null);
    }
    //查询场次详情
    @PostMapping("/{id}")
    public Result selectFlashSessionInfo(@PathVariable("id")Long id){
        FlashPromotionSession session = sessionService.selectFlashSessionInfo(id);
        return Result.success(session);
    }
}
